chrome.webRequest.onBeforeRequest.addListener(
    function(request) {
        var url = request.url.replace('github.githubassets.com', 'github.com');
        return {redirectUrl: url};
    },
    {
        urls: [
            "*://github.githubassets.com/*"
        ]
    },
    ["blocking"]
);

chrome.webRequest.onHeadersReceived.addListener(
    function(response) {
        var headers = ['Content-Security-Policy', 'X-XSS-Protection'];
        return {
            responseHeaders: [
                ...response.responseHeaders.filter(h => headers.indexOf(h.name) === -1),
                {
                    name: 'Access-Control-Allow-Origin',
                    value: 'https://github.com/'
                }
            ]
        };
    },
    {
        urls: [
            "*://github.com/",
            "*://github.com/*"
        ]
    },
    ["blocking", "responseHeaders"]
);
